package cn.jh.common.pojo;

import cn.jh.common.utils.CommonConstants;
import com.google.common.collect.ImmutableMap;

import java.io.Serializable;
import java.util.Map;


public class BaseResponse implements Serializable {

    private static final long serialVersionUID = 1L;

    private String resp_code;

    private String resp_message;

    private Object result;

    public BaseResponse(String resp_code, String resp_message, Object result) {
        this.resp_code = resp_code;
        this.resp_message = resp_message;
        this.result = result;
    }

    public BaseResponse() {
    }

    public String getResp_code() {
        return resp_code;
    }

    public void setResp_code(String resp_code) {
        this.resp_code = resp_code;
    }

    public String getResp_message() {
        return resp_message;
    }

    public void setResp_message(String resp_message) {
        this.resp_message = resp_message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public static BaseResponse success() {
        return success(CommonConstants.SUCCESS, "成功");
    }

    public static BaseResponse successfileexist(Object o) {
        return success(CommonConstants.SUCCESS,"目录已存在，覆盖成功",o);
    }

    public static BaseResponse success(Object o) {
        return new BaseResponse(CommonConstants.SUCCESS, "成功", o);
    }

    public static BaseResponse success(String msg, Object o) {
        return new BaseResponse(CommonConstants.SUCCESS, msg, o);
    }

    public static BaseResponse success(String resp_code, String resp_message, Object result) {
        return new BaseResponse(resp_code, resp_message, result);
    }

    public static BaseResponse error(String msg) {
        return new BaseResponse(CommonConstants.FALIED, msg, null);
    }

    public static BaseResponse error(String resp_code, String resp_message) {
        return new BaseResponse(resp_code, resp_message, null);
    }

    public Map<String, Object> toMap() {
        ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
        builder.put(CommonConstants.RESP_CODE, getResp_code());
        if (resp_message != null) {
            builder.put(CommonConstants.RESP_MESSAGE, getResp_message());
        }
        if (result != null) {
            builder.put(CommonConstants.RESULT, getResult());
        }
        return builder.build();
    }
}
